<?php 
include 'headers.php';
include 'fileOperations.php';
?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/bootstrap.css" type="text/css">
        <title></title>
    </head>
    <body>
        <form class="form-inline" form action="register.php" method="post">            
            <input type="text" class="input-large" name="name" placeholder="Imie i Nazwisko">
            <br>
            <input type="text" class="input-large" name="email" placeholder="Email">
            <br>
            <input type="password" name="passa" class="input-large" placeholder="Hasło">
            <br>
            <input type="password" name ="passb" class="input-large" placeholder=" Powtórz hasło">
            <br>
            
            <br>
            <button type="submit" name="register" value="register" class="btn">Rejestruj</button>
      </form>
        <?php
        
        if(isset($_POST['email']) and isset($_POST['name']) and isset($_POST['passa']) and isset($_POST['passb']))
        {
            $emailCheck=openFile($_POST['email']);
            if($_POST['email']!==$emailCheck[2])
            {
                if($_POST['passa']==$_POST['passb'])
                {
                    if(isset($_POST['register']))
                    { 
                        writeFile($_POST['email'], $_POST['name'], $_POST['passa']);
                    }
                }
                elseif( isset($_POST['passa']) and isset($_POST['passb']))
                {
                    echo "Hasła są różne!";
                }
            }
            elseif($_POST['email']===$emailCheck[2])
            {
                echo "Email już zarejestrowany!";
            }
        }
        
        ?>
    </body>
</html>
